$(document).ready(function(){
    $('.delete_cart').click(function(){
        var cart_id = $(this).attr('cart_id');
        var array_attr = {confirm_delete_cart:"confirm_delete_cart", cart_id:cart_id}; 
        open_modal_confirm('Xác nhận', 'Bạn có chắc chắn muốn xóa...', array_attr);
    });

    $('button[confirm_delete_cart=confirm_delete_cart]').live('click',function(){
        var cart_id = $(this).attr('cart_id');
        $.ajax({
                url:admin_url + 'ajax/delete_cart',
                type:'post',
                data:{cart_id:cart_id},
                success:function(data){
                    location.reload(); 
                }
            });
    });
    
    $('a[change_status_cart=change_status_cart]').live('click',function(){
        var cart_id = $(this).attr('cart_id');
        var status = $(this).attr('status');
        var $this = $(this);
        $.ajax({
            url:admin_url + 'ajax/get_status_cart',
            type:'post',
            data:{cart_id:cart_id},
            success:function(data){
                var _this = $this;
                _this.after(data);
            }
        });
    });
    
    $('select.select_change_status_cart').live('change',function(){
        var status = $(this).val();
        var cart_id = $(this).attr('cart_id');
        var $this = $(this);
        if(status != "")
        {
            $.ajax({
                url:admin_url + 'ajax/change_status_cart',
                type:'post',
                data: {status:status, cart_id:cart_id},
                success:function(data){
                    var obj = JSON.parse(data);
                    var _this = $this;
                    var html = '<a cart_id = "'+cart_id+'" status = "'+status+'" change_status_cart="change_status_cart" href="javascript:void(0)" class="btn '+obj.color+'">'+obj.title+'</a>';
                    _this.parent('div.div_status_cart').html(html);
                }
            });
        }
    });
    
    $('p.close_change_status_cart').live('click',function(){
        $(this).parent('div.div_status_cart').find('select').remove();
        $(this).remove();
    });
    
    
});